#include "StandShoot.h"
#include "Convert.h"



CStandShoot::CStandShoot()
{
	currentStatus_ = SOLDIER_SHOOT_RIGHT_UP;
	loadSprites();
}

CStandShoot::CStandShoot(D3DXVECTOR3 position)
{
	currentStatus_ = SOLDIER_SHOOT_RIGHT_UP;
	this->position_ = position;
	loadSprites();
};

CStandShoot::~CStandShoot()
{
}

float CStandShoot::getAngleWithPlayer(D3DXVECTOR3 playerPostion)
{
	// Position Player  .
	//					|\
	//					| \<--hypotenuse
	//		edge side-->|  \ 	
	//					|__<\.Position StandShoot
	//

	double hypotenuse = sqrt(
		pow((playerPostion.x - this->position_.x), 2)
		+
		pow((playerPostion.y - this->position_.y), 2)
		);

	double edgeSide = sqrt(
		pow((playerPostion.x    -  playerPostion.x), 2)
		+
		pow((this->position_.y  -  playerPostion.y), 2)
		);
	double radAngle = asin(edgeSide / hypotenuse);

	return (float)radAngle * (180 / PI);
}

void CStandShoot::AI(D3DXVECTOR3 playerPosition)
{
	int degAngle = getAngleWithPlayer(playerPosition);
	if (playerPosition.x <= this->position_.x)					// Player.Position.x > StandShoot.Postion.x
	{
		if (playerPosition.y <= this->position_.y)						// Player.Position.y > StandShoot.Position.y
		{
			if (0  <= degAngle && degAngle < 30)							currentStatus_ = SOLDIER_SHOOT_LEFT_UP;
			if (30 <= degAngle && degAngle < 60)							currentStatus_ = SOLDIER_SHOOT_LEFT_TOP;
			if (60 <= degAngle && degAngle <=90)							currentStatus_ = SOLDIER_SHOOT_LEFT_LEFT_TOP;
		}
		else															// Player.Position.y < StandShoot.Position.y
		{
			if (0 <= degAngle && degAngle < 30)								currentStatus_ = SOLDIER_SHOOT_LEFT_DOWN;
			if (30 <= degAngle && degAngle < 60)							currentStatus_ = SOLDIER_SHOOT_LEFT_BOT;
			if (60 <= degAngle && degAngle <=90)							currentStatus_ = SOLDIER_SHOOT_LEFT_LEFT_BOT;
		}
	}
	else														// Player.Position.x > StandShoot.Postion.x							
	{
		if (playerPosition.y <= this->position_.y)						// Player.Position.y > StandShoot.Position.y
		{
			if (0  <= degAngle && degAngle < 30)							currentStatus_ = SOLDIER_SHOOT_RIGHT_UP;
			if (30 <= degAngle && degAngle < 60)							currentStatus_ = SOLDIER_SHOOT_RIGHT_TOP;
			if (60 <= degAngle && degAngle <=90)							currentStatus_ = SOLDIER_SHOOT_RIGHT_RIGHT_TOP;
		}
		else															// Player.Position.y < StandShoot.Position.y
		{
			if (0  <= degAngle && degAngle < 30)							currentStatus_ = SOLDIER_SHOOT_RIGHT_DOWN;
			if (30 <= degAngle && degAngle < 60)							currentStatus_ = SOLDIER_SHOOT_RIGHT_BOT;
			if (60 <= degAngle && degAngle <=90)							currentStatus_ = SOLDIER_SHOOT_RIGHT_RIGHT_BOT;
		}
	}

}

int CStandShoot::HealthyState()
{
	return 0;
}
void CStandShoot::loadSprites()
{
	spriteVector_.push_back(new CSprite(L"Enemy//BOT1.png", 1, 5, 5));
}
void CStandShoot::Update(DWORD deltaTime)
{
	// shoot player
	
}
void CStandShoot::Render()
{
	if (currentStatus_ == SOLDIER_SHOOT_RIGHT_UP || currentStatus_ == SOLDIER_SHOOT_LEFT_DOWN)
		spriteVector_[0]->Render(2, 3, this->position_);
	if (currentStatus_ == SOLDIER_SHOOT_RIGHT_TOP || currentStatus_ == SOLDIER_SHOOT_RIGHT_RIGHT_TOP)
		spriteVector_[0]->Render(4, 5, this->position_);
	if (currentStatus_ == SOLDIER_SHOOT_RIGHT_BOT || currentStatus_ == SOLDIER_SHOOT_RIGHT_RIGHT_BOT)
		spriteVector_[0]->Render(1, -1, this->position_);
	
}
int CStandShoot::setStatus()
{
	return 0;
}